#include "widget.h"
#include "ui_widget.h"

#include <QShortcut>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QShortcut* shortCut1 = new QShortcut(this);
    shortCut1->setKey(QKeySequence("-"));

    QShortcut* shortCut2 = new QShortcut(this);
    shortCut2->setKey(QKeySequence("="));

    //按下快捷键，发出信号，执行槽函数
    connect(shortCut1,&QShortcut::activated,this,&Widget::subValue);
    connect(shortCut2,&QShortcut::activated,this,&Widget::addValue);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::addValue()
{
    int v = ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(v+5);
}

void Widget::subValue()
{
    int v = ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(v-5);
}


void Widget::on_horizontalSlider_valueChanged(int value)
{
    QString s = QString::number(value);
    ui->label->setText("当前值为"+s);
}
